package ui;

import services.InventoeyServicempl;
import vo.Contract;
import vo.Inventory;

import java.util.List;
import java.util.Scanner;

public class InventoryLogin {//库存页面
   static InventoeyServicempl inventoeyServicempl=new InventoeyServicempl();
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
            case 4:
                Inventory inventory1=getcustombyid();
                System.out.println(inventory1);
                break;
            case 5:
                List<Inventory> list=getall();
                for(Inventory inventory:list){
                    System.out.println(inventory);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }

    private static boolean add() {
        System.out.println("请输入商品编号:");
        int inventory_id=scanner.nextInt();
        System.out.println("请输入商品名称:");
        String name=scanner.nextLine();
        System.out.println("请输入商品剩余数量");
        int count=scanner.nextInt();
        Inventory inventory=new Inventory(inventory_id,name,count);
       return inventoeyServicempl.add(inventory);
    }

    private static boolean delet() {
        System.out.println("请输入商品编号:");
        int inventory_id=scanner.nextInt();
        Inventory inventory=new Inventory(inventory_id);
        return inventoeyServicempl.delete(inventory);
    }

    private static boolean modify() {  //通过商品编号(id)查找到要变的库存信息
        System.out.println("请输入商品编号:");
        int inventory_id=scanner.nextInt();
        System.out.println("请输入商品名称:");
        String name=scanner.nextLine();
        System.out.println("请输入商品剩余数量");
        int count=scanner.nextInt();
        Inventory inventory=new Inventory(inventory_id,name,count);
        return inventoeyServicempl.modify(inventory);
    }

    private static Inventory getcustombyid() { //商品编号(id)查询
        System.out.println("请输入商品编号:");
        int inventory_id=scanner.nextInt();
        return inventoeyServicempl.getcustombyid(inventory_id);
    }

    private static List<Inventory> getall() {
        return inventoeyServicempl.getall();
    }
}
